//turret.txt - Simple script for turrets
//Cell 0,1 - Stuff done flag. If both 0, nothing. Otherwise If non-zero, this 
//turret wont attack. If the turret is itself attacked, will set the not-attack setting back to 0.
//Cell 2,3 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.

begincreaturescript;

short i,target;
short last_abil;

body;

beginstate INIT_STATE;
	set_name(ME,"Bride of Travald");
	set_boss_level(ME,2);
	place_particle_num(ME,7,12,6);
	set_walk_speed(ME,0);
	
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	sf(55,7,1);
	erase_char(29);
	erase_char(30);
	
	if (gf(55,14) == 0)
		begin_talk_mode(78);
		else print_str_color("A shade is crushed under a pile of rock.",2);
break;

beginstate START_STATE; 
	if (gf(55,14) > 0)
		end();

	if ((get_attitude(ME) >= 10) && (char_ok(29) == FALSE) && (get_nearest_party_char(9) < 0)) {
		summon_creature(21);
		set_name(29,"Hunter Shade");
		set_level(29,25);
		set_boss_level(29,-1);
		set_attack_bonus(29,6);
		set_summon_level(29,1);
		
		set_resistance(29,0,90);
		}
	if ((get_attitude(ME) >= 10) && (char_ok(30) == FALSE) && (get_nearest_party_char(9) < 0)) {
		summon_creature(22);
		set_name(30,"Hunter Shade");
		set_level(30,25);
		set_boss_level(30,-1);
		set_attack_bonus(30,6);
		set_summon_level(30,1);
		
		set_resistance(30,1,90);
		set_resistance(30,2,90);
		set_resistance(30,3,90);
		}
		
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

		
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (gf(55,14) > 0)
		end();
		
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 1)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();
		  	place_particle_num(ME,1,4,8);
			print_named_str(ME,"radiates a cloud of icy particles.");
			pc_heard_sound_delay(165,25);						
	  		create_missile_spiral(151,40,7,2);
	  		damage_nearby(get_ran(get_level(ME) + get_attack_bonus(ME),1,8),7,6,0);
		end();
	  	}
	else if ((get_health(ME) < (get_max_health(ME) * 4) / 5) && (gf(54,25) == 0)) {
		sf(54,25,1);
		print_str_color("The shade waves a hand and utters a word.",2);
		print_str_color("  A nearby sarcophagus shatters.",2);
		spawn_creature(17);
		set_level(25,20);
		set_boss_level(25,1);
		place_particle_num(25,10,7,10);
		set_name(25,"Many-Spirit Shade");

		run_char_animation(2,1,50);	
		pc_heard_sound_delay(187,100);					
		
		kill_object(63,0);
		
		begin_talk_mode(77);
		}
		
	else if ((get_health(ME) < (get_max_health(ME) * 3) / 5) && (gf(54,26) == 0)) {
		sf(54,26,1);
		print_str_color("The shade waves a hand and utters a word.",2);
		print_str_color("  A nearby sarcophagus shatters.",2);
		spawn_creature(18);
		set_level(26,20);
		set_boss_level(26,1);
		place_particle_num(26,10,7,10);
		set_name(26,"Many-Spirit Shade");

		run_char_animation(2,1,50);	
		pc_heard_sound_delay(187,100);					
		
		kill_object(62,0);
		end();
		}
		
	else if ((get_health(ME) < (get_max_health(ME) * 2) / 5) && (gf(54,27) == 0)) {
		sf(54,27,1);
		print_str_color("The shade waves a hand and utters a word.",2);
		print_str_color("  A nearby sarcophagus shatters.",2);
		spawn_creature(19);
		set_level(27,20);
		set_boss_level(27,1);
		place_particle_num(27,10,7,10);
		set_name(27,"Many-Spirit Shade");

		run_char_animation(2,1,50);	
		pc_heard_sound_delay(187,100);						
		
		kill_object(60,0);
		end();
		}
		
	else if ((get_health(ME) < (get_max_health(ME) * 1) / 5) && (gf(54,28) == 0)) {
		sf(54,28,1);
		print_str_color("The shade waves a hand and utters a word.",2);
		print_str_color("  A nearby sarcophagus shatters.",2);
		spawn_creature(20);
		set_level(28,20);
		set_boss_level(28,1);
		place_particle_num(28,10,7,10);
		set_name(28,"Many-Spirit Shade");

		run_char_animation(2,1,50);	
		pc_heard_sound_delay(187,100);					
		
		kill_object(61,0);
		end();
		}

	do_attack();
	turret_heal();
break;

beginstate TALKING_STATE;
	begin_talk_mode(70);
break;